const app = getApp();

Page({
  data: {
   
  },

  onLoad: function () {
    var store_id = wx.getStorageSync("store_id");
    console.log(store_id)
    if(!store_id){
      app.showToast("请登录小程序")
      wx.navigateBack();
    }else{
      this.setData({
        store_id:wx.getStorageSync("store_id")
      })
      this.tableList();
    }
  },

  tableList:function(){
    var t = this;
    app.visit("account/tableList", {
      store_id:t.data.store_id
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        t.setData({
          list:c.data
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  scanCodeEvent: function(e){
    var table_id = e.currentTarget.dataset.id;
    console.log("桌台："+table_id)
    var t = this;
    wx.scanCode({
      onlyFromCamera: true,
      success(res){
        console.log("扫码成功："+JSON.stringify(res))
        app.showToast(JSON.stringify(res.path))
        var path = res.path;
        var n = path.indexOf("=");
        var mp_id = path.substring(n + 1);
        console.log("码牌:"+mp_id)
        if(!table_id){
          app.showToast("餐桌ID不存在");
          return false;
        }else if(!mp_id){
          app.showToast("码牌ID不存在");
          return false;
        }
        app.visit("account/bangDingMaPai", {
          store_id:t.data.store_id,
          table_id:table_id,
          mp_id:mp_id,
        }, "", function(c) {
          console.log(c)
          if(0 == c.code){
            t.setData({
              list:c.data
            })
          }
          app.showToast(c.msg)
        })
      }
    })
  },


});